package com.test.expandablegridview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends Activity {
    List<List<GroupModel>> listList;
    MyAdapter myAdapter = null;
    private MyExpandableListView expandableListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        expandableListView = (MyExpandableListView) findViewById(R.id.elv_listView);
        listList = Uitl.getList();
        myAdapter = new MyAdapter(this, listList, expandableListView);
        expandableListView.setAdapter(myAdapter);
        expandableListView.setOnChildClickListener(onChildClickListener);
    }


    private ExpandableListView.OnChildClickListener onChildClickListener = new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            int columnsPosition = myAdapter.getColumnsPosition();
            Toast.makeText(MainActivity.this, "我点击的是：" + listList.get(groupPosition).get(columnsPosition).getChildModels().get(childPosition).getChildName(), Toast.LENGTH_LONG).show();
            return false;
        }
    };
}
